import { createVNode } from "vue";
// 导入提示方法
import { message, Modal } from "ant-design-vue";
import { ExclamationCircleOutlined } from "@ant-design/icons-vue";
// 导入通过发布接口
import { adoptPetRelease, vetoPetRelease } from "@/api/petAPI";

export const usePetExamine = (getPetDataList) => {
  // 点击通过
  const handleAdopt = (id) => {
    // 二次确认
    Modal.confirm({
      title: "确认提示",
      icon: createVNode(ExclamationCircleOutlined),
      content: "您是否确认通过",
      okText: "确认",
      cancelText: "取消",
      onOk() {
        // 参数
        const params = {
          id,
        };
        // 发送请求通过宠物发布审核
        adoptPetRelease(params)
          .then((res) => {
            if (res.status === 200) {
              message.success("已通过");
              getPetDataList();
            }
            if (res.status === 205) {
              message.success("error：错误");
            }
          })
          .catch((error) => {
            throw new Error(error);
          });
      },
      onCancel() {
        message.info("已取消");
      },
    });
  };

  // 点击否决
  const handleVeto = (id) => {
    // 二次确认
    Modal.confirm({
      title: "确认提示",
      icon: createVNode(ExclamationCircleOutlined),
      content: "您是否确认否决",
      okText: "确认",
      cancelText: "取消",
      onOk() {
        // 参数
        const params = {
          id,
        };
        // 发送请求通过宠物发布审核
        vetoPetRelease(params)
          .then((res) => {
            if (res.status === 200) {
              message.success("已否决");
              getPetDataList();
            }
            if (res.status === 205) {
              message.success("error：错误");
            }
          })
          .catch((error) => {
            throw new Error(error);
          });
      },
      onCancel() {
        message.info("已取消");
      },
    });
  };

  return {
    handleAdopt,
    handleVeto,
  };
};
